package com.aegean.CommercialHotelBookSystem.shop.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import com.aegean.CommercialHotelBookSystem.model.Customer;

/**
 * Application Lifecycle Listener implementation class OnlineCount
 *
 */
public class OnlineCount implements HttpSessionAttributeListener {
	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		String name = event.getName();
		HttpSession session = event.getSession();
		ServletContext application = session.getServletContext();
		if (name.equals("Login_User") && name != null ) {
			int onlinecount = (Integer) application.getAttribute("online") + 1;
			application.setAttribute("online", onlinecount);
		} else {
		}

	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
		String name = event.getName();
		HttpSession session = event.getSession();
		ServletContext application = session.getServletContext();
		if (name.equals("Login_User") && name != null) {
			int onlinecount = (Integer) application.getAttribute("online") -1;
			if(onlinecount<1){
				onlinecount=1;
			}
			application.setAttribute("online", onlinecount);
		} else {
		}

	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub

	}
}
